<?php
	class Forum extends Controller{
		function Forum(){
			parent::Controller();
			$this->load->model('messageModel');
			
		}
		function index(){
			$id = $this->uri->segment(2);
			$id=intval($id);
			if(!$id)$id=1;
			$offset = floor(floatval($this->uri->segment(3)));
			if($offset<0)$offset=0;
			$this->load->model('forumModel');
			$data['forum']=$this->forumModel->select($id);
			$data['messages']=$this->messageModel->select($id,$offset);
			
			$pagesize=20;
			$config['base_url'] = base_url().'/forum/'.$id;
			$config['total_rows'] = $data['messages']['recordcount'];
			$config['per_page'] = $pagesize;
			$this->load->library('pagination'); 
			$this->pagination->initialize($config); 
			$data['pager']=$this->pagination->create_links();
			
			$this->load->view('forum',$data);
		}
		function my_message(){
			$id=$this->session->userdata('user_id');
			if(!$id){
				header('location:'.site_url('member/login'));
				return;
			}
			$data['forum']['forum_name']='我的主题帖';
			$data['forum']['desc']='';
			$offset = floor(floatval($this->uri->segment(3)));
			if($offset<0)$offset=0;
			$data['messages']=$this->messageModel->my_message($id,$offset);
			
			$pagesize=20;
			$config['base_url'] = base_url().'/forum/my_message/';
			$config['total_rows'] = $data['messages']['recordcount'];
			$config['per_page'] = $pagesize;
			$this->load->library('pagination'); 
			$this->pagination->initialize($config); 
			$data['pager']=$this->pagination->create_links();
			
			$this->load->view('forum',$data);
		}
		function my_reply(){
			$id=$this->session->userdata('user_id');
			if(!$id){
				header('location:'.site_url('member/login'));
				return;
			}
			$data['forum']['forum_name']='我的回帖';
			$data['forum']['desc']='';
			$offset = floor(floatval($this->uri->segment(3)));
			if($offset<0)$offset=0;
			$data['messages']=$this->messageModel->my_reply_message($id,$offset);
			
			$pagesize=20;
			$config['base_url'] = base_url().'/forum/my_reply/';
			$config['total_rows'] = $data['messages']['recordcount'];
			$config['per_page'] = $pagesize;
			$this->load->library('pagination'); 
			$this->pagination->initialize($config); 
			$data['pager']=$this->pagination->create_links();
			
			$this->load->view('forum',$data);
		}
	}
?>